package travels

import (
	"github.com/gin-gonic/gin"
	"net/http"
	"practice/config"
	"practice/internal/model/dao"
)

type Create struct {
	Title   string `form:"title" json:"title" xml:"title"  binding:"required"`
	Img     string `form:"img" json:"img" xml:"img" binding:"required"`
	Intro   string `form:"intro" json:"intro" xml:"intro" binding:"required"`
	Address string `form:"address" json:"address" xml:"address" binding:"required"`
}

func CreateTravel(c *gin.Context) {
	var json Create
	if err := c.ShouldBindJSON(&json); err != nil {
		c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
		return
	}
	title := json.Title
	img := json.Img
	intro := json.Intro
	address := json.Address
	travel := dao.Travel{
		Title:   title,
		Img:     img,
		Intro:   intro,
		Address: address,
	}
	config.DB.Create(&travel)
	c.JSON(http.StatusOK, gin.H{
		"msg":  "添加成功",
		"data": travel.ID,
	})
}
